package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.ArtifactLoan;
import com.zzyl.nursing.service.IArtifactLoanService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 文物出借管理，用于跟踪和管理文物的出借情况Controller
 *
 * @author success
 * @date 2025-03-21
 */
@Api(tags = "文物出借管理")
@RestController
@RequestMapping("/nursing/loan")
public class ArtifactLoanController extends BaseController {
    @Autowired
    private IArtifactLoanService artifactLoanService;

    /**
     * 查询文物出借列表
     */
    @ApiOperation("查询文物出借列表")
    @PreAuthorize("@ss.hasPermi('nursing:loan:list')")
    @GetMapping("/list")
    public TableDataInfo<List<ArtifactLoan>> list(@ApiParam("文物出借管理") ArtifactLoan artifactLoan) {
        startPage();
        List<ArtifactLoan> list = artifactLoanService.selectArtifactLoanList(artifactLoan);
        return getDataTable(list);
    }

    /**
     * 导出文物出借
     */
    @ApiOperation("导出文物出借")
    @PreAuthorize("@ss.hasPermi('nursing:loan:export')")
    @Log(title = "文物出借管理，用于跟踪和管理文物的出借情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam(value = "文物出借管理") HttpServletResponse response, ArtifactLoan artifactLoan) {
        List<ArtifactLoan> list = artifactLoanService.selectArtifactLoanList(artifactLoan);
        ExcelUtil<ArtifactLoan> util = new ExcelUtil<ArtifactLoan>(ArtifactLoan.class);
        util.exportExcel(response, list, "文物出借管理，用于跟踪和管理文物的出借情况数据");
    }

    /**
     * 获取文物出借详细信息
     */
    @ApiOperation("获取文物出借详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:loan:query')")
    @GetMapping(value = "/{loanId}")
    public R<ArtifactLoan> getInfo(@ApiParam("文物出借管理") @PathVariable("loanId") Integer loanId) {
        return R.ok(artifactLoanService.selectArtifactLoanByLoanId(loanId));
    }

    /**
     * 新增文物出借
     */
    @ApiOperation("新增文物出借")
    @PreAuthorize("@ss.hasPermi('nursing:loan:add')")
    @Log(title = "文物出借管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam("文物出借管理") @RequestBody ArtifactLoan artifactLoan) {
        return toAjax(artifactLoanService.insertArtifactLoan(artifactLoan));
    }

    /**
     * 修改文物出借管
     */
    @ApiOperation("修改文物出借")
    @PreAuthorize("@ss.hasPermi('nursing:loan:edit')")
    @Log(title = "文物出借管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("文物出借管理") @RequestBody ArtifactLoan artifactLoan) {
        return toAjax(artifactLoanService.updateArtifactLoan(artifactLoan));
    }

    /**
     * 删除文物出借
     */
    @ApiOperation("删除文物出借")
    @PreAuthorize("@ss.hasPermi('nursing:loan:remove')")
    @Log(title = "文物出借管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{loanIds}")
    public AjaxResult remove(@ApiParam("文物出借管理") @PathVariable Integer[] loanIds) {
        return toAjax(artifactLoanService.deleteArtifactLoanByLoanIds(loanIds));
    }
}
